<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../layui/css/formSelects-v4.css">
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery.min.js"></script>
</head>
<body>
<div id="story">
    <h2>学期维护</h2>
   <!-- &lt;!&ndash;<h1>{{garden_list.glName}}</h1>&ndash;&gt;
    <input type="hidden" name="glId" id="glId" :value="garden_list.glId">
    <input type="hidden" name="gIId" id="gIId" :value="garden_list.glId">
    <input type="hidden" :value="garden_list.glName" id="gradeName">-->
    <table class="layui-hide" id="tmList" lay-filter="tmList"></table>
</div>

<script>
    var table ;
    layui.config({
        base: '../../layui/'
    }).extend({
        formSelects: 'formSelects-v4'
    });

    layui.use(['table','form','formSelects'], function(){
        table = layui.table;
        var form = layui.form;
        var select = layui.formSelects;

        table.render({
            elem: '#tmList'
            ,url:'http://localhost:9999/Xqwh/index'
            /* ,page: true*/
            ,even : true
            ,id : "tmList"
            ,toolbar:"#toolbarDemo",
            defaultToolbar: []
            ,cols: [[
                {field:'hello',type:'checkbox'}
                ,{field:'tMid', title: '编号'}
                ,{field:'tMyear', title: '学期月份'}
                ,{field:'dictionary',  title: '学期类型',templet:function (d) {
                        return d.dictionary.name;
                    }}
                ,{field:'feeM',  title: '收费月份', sort: true}
                ,{field:'abegins', title: '考勤开始日期'}
                ,{field:'end', title: '考勤结束日期'}
                ,{toolbar: '#barDemo',title:'操作'}
            ]]
        });

        //监听行内的工具条
        table.on('tool(tmList)',function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            /*console.log(data);*/
            if(layEvent === 'del'){ //删除
                layer.confirm('确认删除吗？', function(index){
                    layer.close(index);
                    $.post("http://localhost:9999/Xqwh/xqwhDelete",{tMid:data.tMid},function(d){
                        table.reload("tmList");

                    });
                });
            }else if (layEvent === 'edit'){//TODO 编辑
                $.get('updatetm.html?_'+new Date().getTime(),function (s) {
                    layer.open({
                        type : 1,
                        title : data.feeM+'月份的考勤维护',
                        area:'800px',
                        content:s,
                        anim:4,
                        btn : ['确定','取消'],
                        success:function(){
                            //对表单回填数据
                            form.val('tmForm',data);
                            var time = setInterval(function () {
                                if ($("#did option").length >1) {
                                    $("#did").val(data.dictionary.did);
                                    layui.form.render();
                                    clearInterval(time);
                                }
                            },200)
                        },
                        yes : function () {
                            var str = $("#add_tm_form").serialize();
                            $.get("http://localhost:9999/Xqwh/xqwhUpdate",str,function () {
                                layer.close(layer.index);
                                table.reload('tmList');
                            })
                        }
                    })
                })
            } else if (layEvent === 'detail'){ //TODO 查看详情

            }
        });
        //头工具栏事件
        table.on('toolbar(tmList)', function(obj){
            var h = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'batchDelete': //批量删除
                    /* var data = h.data;
                     if(data.length==0){
                         layer.msg("请选择要删除的内容");
                         return;
                     }
                     layer.confirm("要删除吗",function () {
                         var shan = "?";
                         for(let i of data){
                             shan+=`id=${i.userId}&`;
                         }
                         $.get(`http://localhost:9999/kmsuser/batchDelete${shan}`,function () {
                             layer.close(layer.index);
                             table.reload('userList');
                         });
                     });*/

                    break;
                case 'add':
                    $.get("addtm.html?_"+new Date().getTime(),function (data) {
                        layer.open({
                            type : 1,
                            title : '添加学期',
                            skin : 'layui-layer-molv',
                            anim:5,
                            area : '800px',
                            content : data,
                            btn : ['确定','取消'],
                            yes : function () {
                                var str = $("#add_tm_form").serialize();
                                console.log(str);
                                $.get("http://localhost:9999/Xqwh/xqwhAdd",str,function () {
                                    layer.close(layer.index);
                                    table.reload('tmList');
                                });
                            }
                        })

                    });
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
            };
        });

    });

</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加</button>
        <!--<button class="layui-btn layui-btn-sm" lay-event="batchDelete"><i class="layui-icon layui-icon-delete"></i> 批量删除</button>-->
    </div>
</script>

<script type="text/html" id="barDemo">
    <a lay-event="edit"><i class="layui-icon layui-icon-edit"></i></a>
    <a href="javascript:void(0)" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
</script>

<!--<script type="text/html" id="shifou">
    <input type="checkbox" name="locked" value="{{d.locked}}" title="启用" lay-filter="roleTable" {{d.locked == 1 ? 'checked' : ''}}>
</script>-->

</body>
</html>